package com.jspx.txweb.result;

import com.jspx.txweb.Action;
import com.jspx.txweb.ActionInvocation;
import com.jspx.txweb.dispatcher.Dispatcher;
import com.jspx.util.QRCodeUtil;
import com.jspx.utils.StringUtil;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

/**
 * 采用 com\google\zxing  包,需要加入这个包
 */
public class QRCodeResult extends ResultSupport
{
    public void execute(ActionInvocation actionInvocation) throws Exception
    {
        Action action = actionInvocation.getActionProxy().getAction();
        String qrCode = (String)action.getResult();
        if (StringUtil.isNULL(qrCode)) return;
        String contentType = "image/jpg; charset=" + Dispatcher.getEncode();
        HttpServletResponse response = action.getResponse();
        response.setCharacterEncoding(Dispatcher.getEncode());
        response.setContentType(contentType);
        ServletOutputStream out = response.getOutputStream();
        QRCodeUtil.encode(qrCode,out,"JPG");
    }
}